import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '@/views/layout';

Vue.use(VueRouter)

// // 包装路由函数,添加处理错误方法;
// const originalPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function(location) {
//   return originalPush.call(this, location).catch(err => err);
// };

// // 包装路由函数,添加处理错误方法;
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
//   return originalPush.call(this, location).catch(err => err);
// }

const routes = [{
    path: '/auth-bind-wx', // 授权绑定微信（不登录）
    component: () => import('@/views/wx-auth-man/auth-bind-wx/index'),
    hidden: true
  },
  {
    path: '/auth-bind-success', // 授权绑定微信成功（不登录）
    component: () => import('@/views/wx-auth-man/auth-bind-success/index'),
    hidden: true
  },


  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard-center/dashboard'
  },
  {
    path: '/error',
    component: Layout,
    children: [{
        path: '404',
        component: () => import('@/views/error-page/404'),
        meta: {
          title: '404'
        }
      },
      {
        path: '401',
        component: () => import('@/views/error-page/401'),
        meta: {
          title: '401'
        }
      }
    ]
  },

  /****旅行社-路由--begin************************/
  {
    path: '/travel',
    component: Layout,
    children: [{ // 普通订单
        path: 'order-list',
        component: () => import('@/views/my-travel/business-man/travel-order-list'),
        name: 'TravelOrderList',
        meta: {
          title: '普通订单'
        }
      },
      { // 顺风车订单
        path: 'sfc-order-list',
        component: () => import('@/views/my-travel/business-man/travel-sfc-order-list'),
        name: 'TravelSfcOrderList',
        meta: {
          title: '顺风车订单'
        }
      },
      { // 员工列表
        path: 'staff-list',
        component: () => import('@/views/my-travel/person-center-man/staff-list'),
        name: 'TravelStaffList',
        meta: {
          title: '员工列表'
        }
      },
      { // 订单进度
        path: 'order-progress',
        component: () => import('@/views/my-travel/business-man/order-progress'),
        name: 'TravelOrderProgress',
        meta: {
          title: '订单进度'
        }
      },
      { // 付款申请列表
        path: 'pay-apply-list',
        component: () => import('@/views/my-travel/business-man/pay-apply-list'),
        name: 'PayApplyList',
        meta: {
          title: '付款申请列表'
        }
      },
      { // 交易列表
        path: 'travel-wallet-list',
        component: () => import('@/views/my-travel/business-man/travel-wallet-list'),
        name: 'TravelWalletList',
        meta: {
          title: '交易列表'
        }
      },
      { // 推荐客户列表
        path: 'travel-rec-cus-list',
        component: () => import('@/views/my-travel/travel-rec-cus-list'),
        name: 'TravelRecCusList',
        meta: {
          title: '推荐客户列表'
        }
      },



    ]
  },

  {
    path: '/dashboard-center',
    component: Layout,
    children: [{
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {
          title: '信息概览',
          icon: 'dashboard'
        }
      },
      {
        path: 'trend-list',
        component: () => import('@/views/dashboard/trend-list'),
        name: 'trend-list',
        meta: {
          title: '趋势列表',
          icon: 'trend-list'
        }
      },
      {
        path: 'contract-list',
        component: () => import('@/views/dashboard/contractL-list'),
        name: 'contract-list',
        meta: {
          title: '合同列表',
          icon: 'contract-list'
        }
      }
    ]
  },

  {
    path: '/business',
    component: Layout,
    children: [{
        path: 'sfc-order-list',
        component: () => import('@/views/business-man/sfc-order-list'),
        name: 'SfcOrderList',
        meta: {
          title: '任务大厅'
        }
      },
      {
        path: 'cus-list',
        component: () => import('@/views/business-man/cus-list'),
        name: 'CusList',
        meta: {
          title: '客户列表'
        }
      },
      {
        path: 'order-list',
        component: () => import('@/views/business-man/order-list'),
        name: 'OrderList',
        meta: {
          title: '订单列表'
        }
      },
      {
        path: 'disorder-list',
        component: () => import('@/views/business-man/disorder-list'),
        name: 'DisorderList',
        meta: {
          title: '派车列表'
        }
      },
      {
        path: 'empty-car-list',
        component: () => import('@/views/business-man/empty-car-list'),
        name: 'EmptyCarList',
        meta: {
          title: '空车列表'
        }
      },
      {
        path: 'car-dynamic-list',
        component: () => import('@/views/business-man/car-dynamic-list'),
        name: 'CarDynamicList',
        meta: {
          title: '动态列表'
        }
      },
      {
        path: 'vehicles-position-list',
        component: () => import('@/views/business-man/vehicles-position-list'),
        name: 'VehiclesPositionList',
        meta: {
          title: '车辆轨迹'
        }
      },


      // {// 旅行社-普通订单
      //   path: 'travel-order-list',
      //   component: () => import('@/views/business-man/travel-order-list'),
      //   name: 'TravelOrderList',
      //   meta: { title: '普通订单' }
      // },
      // {// 旅行社-顺风车订单
      //   path: 'travel-sfc-order-list',
      //   component: () => import('@/views/business-man/travel-sfc-order-list'),
      //   name: 'TravelSfcOrderList',
      //   meta: { title: '顺风车订单' }
      // },


    ]
  },

  {
    path: '/logistics-man',
    component: Layout,
    children: [{
        path: 'group-list',
        component: () => import('@/views/logistics-man/group-list'),
        name: 'GroupList',
        meta: {
          title: '小组列表'
        }
      },
      {
        path: 'car-list',
        component: () => import('@/views/logistics-man/car-list'),
        name: 'CarList',
        meta: {
          title: '车辆列表'
        }
      },
      {
        path: 'police-alarm',
        component: () => import('@/views/logistics-man/police-alarm'),
        name: 'PoliceAlarm',
        meta: {
          title: '车辆报警'
        }
      },
      {
        path: 'sfc-empty-car-list',
        component: () => import('@/views/logistics-man/sfc-empty-car-list'),
        name: 'SfcEmptyCarList',
        meta: {
          title: '发布顺风空车'
        }
      },
    ]
  },
  // 系统设置
  {
    path: '/system-man',
    component: Layout,
    children: [{
        path: 'dept-role-list',
        component: () => import('@/views/system-man/dept-role-list'),
        name: 'DeptRoleList',
        meta: {
          title: '部门角色'
        }
      },
      {
        path: 'money-type',
        component: () => import('@/views/system-man/money-type'),
        name: 'moneyType',
        meta: {
          title: '金额类型'
        }
      },
      {
        path: 'custom-type',
        component: () => import('@/views/system-man/custom-type'),
        name: 'CustomType',
        meta: {
          title: '客户类型'
        }
      },
      {
        path: 'leave-type-list',
        component: () => import('@/views/system-man/leave-type-list'),
        name: 'LeaveTypeList',
        meta: {
          title: '休假类型'
        }
      },
      {
        path: 'company-list',
        component: () => import('@/views/system-man/company-list'),
        name: 'ConpanyList',
        meta: {
          title: '公司管理'
        }
      },
      {
        path: 'account-type',
        component: () => import('@/views/system-man/account-type'),
        name: 'AccountType',
        meta: {
          title: '报账类型'
        }
      },
      {
        path: 'maintance-type',
        component: () => import('@/views/system-man/maintance-type'),
        name: 'MaintanceType',
        meta: {
          title: '维修类型'
        }
      },
      {
        path: 'sign-type',
        component: () => import('@/views/system-man/sign-type'),
        name: 'signType',
        meta: {
          title: '品牌类型'
        }
      }
    ]
  },


  {
    path: '/finance-man',
    component: Layout,
    children: [{
        path: 'bank-list',
        component: () => import('@/views/finance-man/bank-list'),
        name: 'BankManagement',
        meta: {
          title: '银行管理'
        }
      },
      {
        path: 'bank-account',
        component: () => import('@/views/finance-man/bank-account'),
        name: 'BankAccount',
        meta: {
          title: '银行记账'
        }
      },
      {
        path: 'staff-reim-list',
        component: () => import('@/views/finance-man/staff-reim-list'),
        name: 'StaffReimList',
        meta: {
          title: '员工报账'
        }
      },
      {
        path: 'in-out-list',
        component: () => import('@/views/finance-man/in-out-list'),
        name: 'inOutList',
        meta: {
          title: '应收应付表'
        }
      },
      {
        path: 'profit-list',
        component: () => import('@/views/finance-man/profit-list'),
        name: 'profitList',
        meta: {
          title: '利润结算表'
        }
      },
      {
        path: 'collection-list',
        component: () => import('@/views/finance-man/collection-list'),
        name: 'CollectionList',
        meta: {
          title: '业务收款'
        }
      },
      {
        path: 'payment-list',
        component: () => import('@/views/finance-man/payment-list'),
        name: 'PaymentList',
        meta: {
          title: '业务付款'
        }
      },
      {
        path: 'collPay-list',
        component: () => import('@/views/finance-man/collPay-list'),
        name: 'CollPayList',
        meta: {
          title: '业务对冲'
        }
      },
      {
        path: 'salary-list',
        component: () => import('@/views/finance-man/salary-list'),
        name: 'SalaryList',
        meta: {
          title: '工资列表'
        }
      },
      {
        path: 'cash-list',
        component: () => import('@/views/finance-man/cash-list'),
        name: 'CashList',
        meta: {
          title: '现金结算'
        }
      }
    ]
  },
  {
    // 人事中心
    path: '/person-man',
    component: Layout,
    children: [
      // 人事中心
      {
        path: 'driver-center',
        component: () => import('@/views/person-man/driver-center'),
        name: 'DriverCenter',
        meta: {
          title: '人事报警'
        }
      },
      // 员工列表
      {
        path: 'staff-list',
        component: () => import('@/views/person-man/staff-list'),
        name: 'StaffList',
        meta: {
          title: '员工列表 '
        }
      },
      // 休假列表
      {
        path: 'leave-list',
        component: () => import('@/views/person-man/leave-list'),
        name: 'LeaveList',
        meta: {
          title: '休假列表 '
        }
      },
    ]
  },
  {
    path: '/office',
    component: Layout,
    children: [{
        path: 'staff-list',
        component: () => import('@/views/user-man/user-list'),
        name: 'userList',
        meta: {
          title: '用户列表'
        }
      },
      {
        path: 'add-user',
        component: () => import('@/views/user-man/add-user'),
        name: 'addUser',
        meta: {
          title: '添加用户'
        }
      },
      {
        path: 'upd-user',
        component: () => import('@/views/user-man/upd-user'),
        name: 'updUser',
        meta: {
          title: '修改用户'
        }
      }
    ]
  },

  {
    path: '/not-found',
    component: () => import('@/views/not-found'),
    hidden: true,
    meta: {
      title: '404'
    }
  },
  {
    path: '*',
    redirect: '/404'
  }
]

// 防止报错 Redirected when going from “/login” to “/home” via a navigation guard
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return routerPush.call(this, location, onResolve, onReject);
  return routerPush.call(this, location).catch(error => error);
}

const router = new VueRouter({
  // mode: 'history',
  scrollBehavior: () => ({
    y: 0
  }),
  base: process.env.BASE_URL,
  routes
});

export default router
